﻿using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace Sayook.Framework.DbCore.SqlModel
{
    /// <summary>
    /// WHERE 表达式接收对象
    /// </summary>
    public sealed class SqlWhere
    {
        private SqlWhere()
        {
        }

        /// <summary>
        /// 条件参数1
        /// </summary>
        public object Value1 { get; set; }

        /// <summary>
        /// 条件参数2
        /// </summary>
        public object Value2 { get; set; }

        /// <summary>
        /// 设置条件 参数传入条件值
        /// </summary>
        /// <typeparam name="T">条件字段类型</typeparam>
        /// <param name="filde">条件字段</param>
        /// <param name="sqlOperator">运算符</param>
        public static SqlWhere Set<T>(T filde, SqlOperator sqlOperator) => null;

        /// <summary>
        /// 设置条件 直接传入条件值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="filde">条件字段</param>
        /// <param name="sqlOperator">运算符</param>
        /// <param name="value">条件值</param>
        public static SqlWhere Set<T>(T filde, SqlOperator sqlOperator, [NotNull] T value)
        {
            return new SqlWhere { Value1 = value };
        }

        /// <summary>
        /// In | NotIn 条件查询
        /// </summary>
        /// <typeparam name="T">条件字段类型</typeparam>
        /// <param name="filde">条件字段</param>
        /// <param name="sqlOperator">运算符</param>
        /// <param name="values">集合</param>
        /// <returns></returns>
        public static SqlWhere Set<T>(T filde, SqlOperator sqlOperator, [NotNull] IEnumerable<T> values)
        {
            return new SqlWhere { Value1 = values };
        }

        /// <summary>
        /// Between 条件查询
        /// </summary>
        /// <typeparam name="T">条件字段类型</typeparam>
        /// <param name="filde">条件字段</param>
        /// <param name="sqlOperator">运算符</param>
        /// <param name="startValue">开始值</param>
        /// <param name="endValue">结束值</param>
        /// <returns></returns>
        public static SqlWhere Set<T>(T filde, SqlOperator sqlOperator, [NotNull] T startValue, [NotNull] T endValue)
        {
            return new SqlWhere { Value1 = startValue, Value2 = endValue };
        }
    }
}